package cn.kilo.trigger.job;

import cn.kilo.domain.model.order.entity.OrderStaffEntity;
import cn.kilo.domain.model.order.vo.OrderStatusVO;
import cn.kilo.domain.service.infterface.IOrderStrategyService;
import cn.kilo.domain.service.order.stock.IOrderStock;
import cn.kilo.trigger.api.IOrderService;
import cn.kilo.trigger.api.dto.order.OrderDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author kilok
 * 更新orderStaff表/
 */
@Slf4j
@Component()
public class UpdateOrderStaffStockJob {

    @Resource
    protected IOrderStock orderStock;

    @Resource
    private IOrderStrategyService orderService;


    @Scheduled(cron = "0/5 * * * * ?")
    public void exec(){
        try{
//            log.info("更新orderStaff");
            OrderStaffEntity orderStaffEntity=orderStock.takeQueueValue();
            if(null==orderStaffEntity) {
                return;
            }
            log.info("更新;{}",orderStaffEntity);
            orderStock.updateOrderStaffStockQueue(orderStaffEntity);
        }catch (Exception e){
            log.info("定时任务，更新orderStaff出现错误",e);
        }
    }

    // TODO: 2024/5/29 等委托方完善骑手机制之后，关于订单的分配可以适应延时队列+LRU 保证每一个骑手都可以均匀分配到订单
    // TODO: 2024/5/29 LRU 双向链表+map
    @Scheduled(cron = "0 0/1 * * * ?")
    public void rollOrder(){
//        OrderStatusVO orderStatusVO=orderStock.takeOrderInfo();
//        if(null==orderStatusVO) {
//            return;
//        }
//        orderService.offerOrderToStaff(orderStatusVO.getRidgepole(),orderStatusVO.getOrderId());
    }
}
